package com.samoilovich.belarustoday.mainscreen.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.samoilovich.belarustoday.R;
import com.samoilovich.belarustoday.afisha.AfishaActivity;
import com.samoilovich.belarustoday.basefragments.BaseFragment;
import com.samoilovich.belarustoday.basefragments.BaseFragmentActivity;
import com.samoilovich.belarustoday.mainscreen.MainActivity;
import com.samoilovich.belarustoday.news.NewsActivity;
import com.samoilovich.belarustoday.rates.RatesActivity;
import com.samoilovich.belarustoday.tech.TechActivity;

public class CategoryFragment extends BaseFragment {
    private ImageView mNewsButton;
    private ImageView mAfishaButton;
    private ImageView mTechButton;
    private ImageView mRatesButton;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mRootView = inflater.inflate(R.layout.fragment_main_screen_categories, null);
        prepareViews();
        setOnNewsClickListener();
        setOnAfishaClickListener();
        setOnTechClickListener();
        setOnRatesClickListener();

		return mRootView;
	}

    // -----------------------------------------------------------------------------------
    // -----------------------------------------------------------------------------------
    private void prepareViews() {
    	(mRootView.findViewById(R.id.view_action)).setVisibility(View.GONE);
    	((TextView) mRootView.findViewById(R.id.textView_title)).setText(R.string.app_name);

        Button optionsButton = (Button) mRootView.findViewById(R.id.button_option);
        (mRootView.findViewById(R.id.view_action)).setVisibility(View.GONE);
        optionsButton.setVisibility(View.VISIBLE);
        optionsButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                ((BaseFragmentActivity) getActivity()).setOptionsFragment(getString(R.string.main_label));
            }
        });
    }

    // -----------------------------------------------------------------------------------
    private void setOnNewsClickListener() {
        mNewsButton = (ImageView) mRootView.findViewById(R.id.imageView_news);

        mNewsButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), NewsActivity.class);
				startActivity(intent);
			}
		});
    }
    
    private void setOnAfishaClickListener() {
        mAfishaButton = (ImageView) mRootView.findViewById(R.id.imageView_afisha);

        mAfishaButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), AfishaActivity.class);
				startActivity(intent);
			}
		});
    }
    
    private void setOnTechClickListener() {
        mTechButton = (ImageView) mRootView.findViewById(R.id.imageView_tech);

        mTechButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), TechActivity.class);
				startActivity(intent);
			}
		});
    }
    
    private void setOnRatesClickListener() {
        mRatesButton = (ImageView) mRootView.findViewById(R.id.imageView_rates);

        mRatesButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), RatesActivity.class);
				startActivity(intent);
			}
		});
    }

}
